package threading;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: xwl
 * Date: 2023-08-08
 * Time: 14:05
 */
public class ThreadDemo8 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread( () -> {
            while (true) {
//                // 为了防止hello吧线程状态冲掉,先注释掉里面的语句
//                System.out.println("hello t");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        // 在启动之前,获取线程状态 -> NEW
        System.out.println(t.getState());

        t.start();

        Thread.sleep(2000);
        // 当在执行while(true)时,状态 -> RUNNABLE
        // 执行Thread.sleep时,状态 -> TIMED_WAITING
        System.out.println(t.getState());
//        // 在线程完成后,获取线程状态 -> TERMINATED
//        System.out.println(t.getState());
    }

}
